package com.edu.bean;
/*
 * @Author:princess
 * @Date 2023/10/23 10 23 19:13
 *
 */

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class User implements BeanNameAware, ApplicationContextAware, InitializingBean, DisposableBean {
    private int userId;
    private String username;
    private String password;
    private String beanId;

    @Override
    public String toString() {
        return "User{" +
                "userId=" + userId +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        System.out.println("2 执行了set 方法");
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public User() {
        System.out.println("1 执行构造方法");
    }

    public User(int userId, String username, String password) {
        this.userId = userId;
        this.username = username;
        this.password = password;
    }

    public void setBeanName(String s) {
        System.out.println("3 执行了 BeanNameAware接口的方法");
        beanId = s;
    }

    public String getBeanId() {
        return beanId;
    }

    public void setBeanId(String beanId) {
        this.beanId = beanId;
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("4 执行了 ApplicationContextAware接口的方法");
    }

    public void afterPropertiesSet() throws Exception {
        System.out.println("6 执行 InitializingBean 接口 规定的初始化方法");
    }

    public void init(){
        System.out.println("7 执行了自定义的初始化方法");
    }

    public void sayHi(){
        System.out.println("9.从容器取出来，调用自身的业务方法 ");
    }

    public void destroy() throws Exception {
        System.out.println("10.执行 DisposableBean接口的 销毁方法");
    }

    public void destory(){
        System.out.println("11 执行了自定义的销毁方法");
    }
}
